package org.jeecg.modules.simulator.factory;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.simulator.factory.train.load.TrainPhysicsLoader;
import org.jeecg.modules.simulator.jsonot.TrainType;
import org.jeecg.modules.simulator.mapper.SimTrainTypeMapper;
import org.jeecg.modules.simulator.model.train.TrainPhysics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @program: simulator-b20240918
 * @description:
 * @author: renzhg
 * @create: 2024-11-06 15:34
 **/
@Service
@Slf4j
public class LoadTrainTypeService implements TrainPhysicsLoader {
    @Getter
    @Setter
    Map<String, TrainPhysics> trainPhysicsMap = new HashMap<>();

    @Resource
    SimTrainTypeMapper simTrainTypeMapper;
    @Getter
    List<TrainPhysics> trainPhysicsList = new ArrayList<>();
    public void initTrainPhyMap() {
        trainPsread();

        trainPhysicsMap= trainPhysicsList.stream().collect(Collectors.toMap(TrainPhysics::getTrainName, e -> e));

    }
    @Override
    public void trainPsread() {


        List<TrainType> allTrainType = simTrainTypeMapper.getAllTrainType();
        for (TrainType type : allTrainType) {
            TrainPhysics trainPhysics = new TrainPhysics();
            TrainType trainType = type;
            trainPhysics.setTrainName(trainType.getName());
            trainPhysics.setCapacity(trainType.getCapacity());
            trainPhysics.setArea(trainType.getArea());
            trainPhysics.setNumberOfPeopleSMeter(trainType.getNumberOfPeopleSMeter());
            trainPhysics.setMaxFullLoad(trainType.getMaxFullload());
            trainPhysics.setMaxSpeed(trainType.getMaxSpeed());
            trainPhysics.setCarriagesNumber(trainType.getCarriagesNumber());
            trainPhysicsList.add(trainPhysics);
        }


    }
}
